package com.atguigu.srb.gateway.config;



import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;


@Configuration
public class GatewayConfig {

    @Bean
    public CorsWebFilter corsWebFilter(){

        UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedMethod("*");//那些请求方式允许跨域访问
        config.addAllowedOrigin("*");//允许哪些orgin跨域访问
        config.addAllowedHeader("*");//允许携带哪些请求头跨域访问
        config.setAllowCredentials(true);//是否允许携带cookie跨域访问
        configurationSource.registerCorsConfiguration("/**",config);

        return new CorsWebFilter(configurationSource);

    }
}
